<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.keywords" placeholder="商家名称、会员账号" clearable style="width: 200px"></el-input>
      </el-form-item>
      <el-form-item label="起始时间">
				<el-date-picker
          v-model="dataForm.startTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="起始时间">
			  </el-date-picker>
			</el-form-item>
			<el-form-item label="结束时间">
				<el-date-picker
          v-model="dataForm.endTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="结束时间">
			  </el-date-picker>
			</el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <!-- <el-button v-if="isAuth('goods:shoppinggoods:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button> -->
        <!-- <el-button v-if="isAuth('goods:shoppinggoods:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="addTime"
        header-align="center"
        align="center"
        label="注册时间"
        width="160">
      </el-table-column>
      <el-table-column
        prop="trueName"
        header-align="center"
        align="center"
        label="商家名称">
      </el-table-column>
      <el-table-column
        prop="userName"
        header-align="center"
        align="center"
        label="会员账号"
        width="160px">
      </el-table-column>
      <el-table-column
        prop="realName"
        header-align="center"
        align="center"
        label="会员负责人">
      </el-table-column>
      <el-table-column
        prop="userType"
        header-align="center"
        align="center"
        label="会员类型">
        <template slot-scope="scope">
           <span>
             {{scope.row.userType == 1 ? '区域运营商'
               :scope.row.userType == 2 ? '普通联盟店'
               :scope.row.userType == 3 ? '消费者'
               :scope.row.userType == 4 ? 'VIP会员'
               :scope.row.userType == 5 ? '中级版联盟店'
               :scope.row.userType == 6 ?'高级版联盟店'
               :scope.row.userType == 7 ?'城市合伙人'
               :scope.row.userType == 8 ? '城市合伙人联盟店':'未知'}}
           </span>
        </template>
      </el-table-column>
      <el-table-column
        prop="balanceMoney"
        header-align="center"
        align="center"
        label="会员总余额">
        <template slot-scope="scope">
          <span v-if="scope.row.balanceMoney != null">￥ {{scope.row.balanceMoney}}</span>
          <span v-if="scope.row.balanceMoney == null">￥ 0</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="notExtract"
        header-align="center"
        align="center"
        label="未提现">
        <template slot-scope="scope">
          <span v-if="scope.row.notExtract != null">￥ {{scope.row.notExtract}}</span>
          <span v-if="scope.row.notExtract == null">￥ 0</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="yesExtract"
        header-align="center"
        align="center"
        label="已提现"
        width="160px">
        <template slot-scope="scope">
          <span v-if="scope.row.yesExtract != null">￥ {{scope.row.yesExtract}}</span>
          <span v-if="scope.row.yesExtract == null">￥ 0</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="commissionMoney"
        header-align="center"
        align="center"
        label="推广余额">
        <template slot-scope="scope">
          <span v-if="scope.row.commissionMoney != null">￥ {{scope.row.commissionMoney}}</span>
          <span v-if="scope.row.commissionMoney == null">￥ 0</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="status"
        header-align="center"
        align="center"
        label="会员状态">
        <template slot-scope="scope">
          <span v-if="scope.row.userType == 1 || scope.row.userType == 3 || scope.row.userType == 4 || scope.row.userType == 7">
            <span v-if="scope.row.status == 0">正常</span>
            <span v-if="scope.row.status == 1">不正常</span>
            <span v-if="scope.row.status == 5">被冻结</span>
            <span v-if="scope.row.status == 7">注册未登陆</span>
          </span>
          <span v-if="scope.row.userType == 2|| scope.row.userType == 5 || scope.row.userType == 6 || scope.row.userType == 8">
            <span v-if="scope.row.status == 0">未审核</span>
            <span v-if="scope.row.status == 1">审核通过</span>
            <span v-if="scope.row.status == 2">审核不通过</span>
            <span v-if="scope.row.status == 5">被冻结</span>
            <span v-if="scope.row.status == 7">注册未登陆</span>
          </span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">查看</el-button>
          <el-button type="text" size="small" @click="addOrUpdateHandle1(scope.row.id)">打款</el-button>
          <!-- <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <updatefinance v-if="addOrUpdateVisible" ref="updatefinance" @refreshDataList="getDataList"></updatefinance>
  </div>
</template>

<script>
  import AddOrUpdate from './finance-add-or-update'
  import updatefinance from './updatefinance'
  export default {
    data () {
      return {
        dataForm: {
          keywords: '',
          startTime: '',
          endTime: '',
          priceType: '',
          goodsStatuses: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate,
      updatefinance
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/user/finance/queryFinanceList'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keywords': this.dataForm.keywords,
            'startTime': this.dataForm.startTime,
            'endTime': this.dataForm.endTime
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.data.list
            this.totalPage = data.data.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 打款
      addOrUpdateHandle1 (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.updatefinance.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/goods/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
